package com.yanqu.road.server.cmd.specialcookboy;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.specialcookboy.SpecialCookBoyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.specialcookboy.SpecialCookBoyModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SPECIAL_COOK_BOY_SHARE_ADD_TIME, desc = "小当家特色服分享增加时间")
public class SpecialCookBoyShareAddTimeCmd  extends AbstractCommand {

    private int level;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SpecialCookBoyProto.ShareSpecialCookBoySmallGameReq msg = SpecialCookBoyProto.ShareSpecialCookBoySmallGameReq.parseFrom(packet.getBytes());
        level = msg.getLevelId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(SpecialCookBoyModule.class).shareAddTime(level);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret!=0){
            SpecialCookBoyProto.ShareSpecialCookBoySmallGameResp.Builder builder = SpecialCookBoyProto.ShareSpecialCookBoySmallGameResp.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SPECIAL_COOK_BOY_SHARE_ADD_TIME,builder);
        }
    }
}
